<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

require_once APPPATH . 'controllers/admin.php';

/**
 * Контроллер просмотра и изменения настроек видео партнерок
 *
 * @package CoreFramework
 * @version 1.0
 * @author Gennadiy Kozlenko
 */
class Admin_Partners_Settings extends Admin {

    /**
     * Приоритет партнерских программ
     * @var array
     */
    private $partners = array(
        'kinoperez',
        'dircash',
        'loadpartners'
    );
     
    /**
     * Конструктор класса
     *
     * @access public
     * @return Admin_Partners_Settings
     */
    function Admin_Partners_Settings() {
        parent::Admin();
        $this->set_menu(5, 4);
    } // end Admin_Partners_Settings
     
    /**
     * Метод по умолчанию
     *
     * @access public
     */
    function index() {
        $data = array();
        // Стандартные поля
        $use_kinoperez = $this->variables->get('use_kinoperez');
        $kinoperez_id = $this->variables->get('kinoperez_id');
        $kinoperez_shop = $this->variables->get('kinoperez_shop');
        $use_dircash = $this->variables->get('use_dircash');
        $dircash_id = $this->variables->get('dircash_id');
        $dircash_shop = $this->variables->get('dircash_shop');
        $use_loadpartners = $this->variables->get('use_loadpartners');
        $loadpartners_id = $this->variables->get('loadpartners_id');
        $loadpartners_shop = $this->variables->get('loadpartners_shop');
        /*
        $partners_priority = $this->variables->get('partners_priority');
        $partners = array_filter(explode(',', $partners_priority));
        $partners = array_unique(array_merge($partners, $this->partners));
        $partners_priority = implode(',', $partners);
        */
        // Валидируем и, если нужно, изменяем
        if (false !== $this->input->post('edit')) {
            // Получаем из поста поля
            $use_kinoperez = (bool) $this->input->post('use_kinoperez');
            $kinoperez_id = trim($this->input->post('kinoperez_id'));
            $kinoperez_shop = trim($this->input->post('kinoperez_shop'));
            $use_dircash = (bool) $this->input->post('use_dircash');
            $dircash_id = trim($this->input->post('dircash_id'));
            $dircash_shop = trim($this->input->post('dircash_shop'));
            $use_loadpartners = (bool) $this->input->post('use_loadpartners');
            $loadpartners_id = trim($this->input->post('loadpartners_id'));
            $loadpartners_shop = trim($this->input->post('loadpartners_shop'));
            //$partners_priority = trim($this->input->post('partners'));
            // Сохраняем
            $this->variables->set('use_kinoperez', $use_kinoperez ? 'yes' : 'no');
            $this->variables->set('kinoperez_id', $kinoperez_id);
            $this->variables->set('kinoperez_shop', $kinoperez_shop);
            $this->variables->set('use_dircash', $use_dircash ? 'yes' : 'no');
            $this->variables->set('dircash_id', $dircash_id);
            $this->variables->set('dircash_shop', $dircash_shop);
            $this->variables->set('use_loadpartners', $use_loadpartners ? 'yes' : 'no');
            $this->variables->set('loadpartners_id', $loadpartners_id);
            $this->variables->set('loadpartners_shop', $loadpartners_shop);
            //$this->variables->set('partners_priority', $partners_priority);
            $this->set_message($this->lang->line('edit_settings_succ'), 'info', true);
            $this->redirect($this->get_controller());
        }
        // Забиваем в дату поля
        $this->load->helper('element');
        $data['use_kinoperez'] = create_checkbox('use_kinoperez', 'yes' == $use_kinoperez);
        $data['kinoperez_id'] = htmlspecialchars($kinoperez_id);
        $data['kinoperez_shop'] = htmlspecialchars($kinoperez_shop);
        $data['use_dircash'] = create_checkbox('use_dircash', 'yes' == $use_dircash);
        $data['dircash_id'] = htmlspecialchars($dircash_id);
        $data['dircash_shop'] = htmlspecialchars($dircash_shop);
        $data['use_loadpartners'] = create_checkbox('use_loadpartners', 'yes' == $use_loadpartners);
        $data['loadpartners_id'] = htmlspecialchars($loadpartners_id);
        $data['loadpartners_shop'] = htmlspecialchars($loadpartners_shop);
        //$data['partners_priority'] = htmlspecialchars($partners_priority);
        // Выводим
        $this->set_content($this->parser->parse('admin/partners_settings.html', $data, true));
        $this->display();
    } // end index
     
}
